package com.itump.base.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.itump.base.util.web.SpringApplicationContextHoldingListener;

public final class SpringUtils {
	
	public final static ApplicationContext getApplicationContext() {
		return Holder.ctx;
	}
	
	private final static class Holder {
		private final static ApplicationContext ctx = ctx();
		private final static ApplicationContext ctx() {
			ApplicationContext ctx0 = SpringApplicationContextHoldingListener.getOnce(new SpringUtils());
			if (ctx0 == null) {
				return new ClassPathXmlApplicationContext("classpath*:applicationContext*.xml");
			} else {
				return ctx0;
			}
		}
	}
	
	private SpringUtils(){}
}
